﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Aliphant.Common.Helper;
using Aliphant.Datas;

namespace Aliphant.Common.Managers
{
    public class ConfigManager : Singleton<ConfigManager>
    {
        public ConfigManager()
        {
            Load();
        }

        public AppSettingConfig Settings { get; private set; } = new AppSettingConfig();

        public bool ExitApplication { get; set; } = false;

        public void Load()
        {
            string path = DomainHelper.GetConfigPath();
            JsonHelper.ReadJson(path, out AppSettingConfig? settings);

            if (settings != null)
            {
                Settings = settings;
            }
        }

        public void Save()
        {
            string path = DomainHelper.GetConfigPath();
            var settings = Settings;
            JsonHelper.SaveToJson<AppSettingConfig>(ref settings, path);
        }
    }
}
